name: Build Linux Distributable

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v2
    - name: Fetch entire repository
      run: git fetch --prune --unshallow
    - name: Install prerequisites
      run: sudo apt-get install libgl1-mesa-dev
    - name: Make
      run: make staticbindist
    - name: Determine version
      id: get_version
      run: |
        OPENMSX_MAJOR_VERSION=`python3 build/version.py`
        OPENMSX_BUILD_REVISION=`fgrep "Revision string:" derived/version.log | sed -e "s/.*: //"`
        OPENMSX_VERSION=$OPENMSX_MAJOR_VERSION-$OPENMSX_BUILD_REVISION
        echo ::set-output name=OPENMSX_VERSION::$OPENMSX_VERSION
    - name: Create redistributable zip
      run: |
        cd derived/x86_64-linux-opt-3rd/bindist/install
        zip -r ../openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-x86_64-linux-opt-3rd.zip *
    - name: Upload redistributable zip
      uses: actions/upload-artifact@v1
      with:
        name: openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-x86_64-linux-opt-3rd.zip
        path: derived/x86_64-linux-opt-3rd/bindist/openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-x86_64-linux-opt-3rd.zip
